package com.dream.vo.app;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;

import javax.validation.GroupSequence;
import javax.validation.constraints.Pattern;

import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotBlank;

import com.dream.model.app.AppAbstractUser;
import com.dream.model.app.AppAbstractUser.UserStatus;
import com.dream.utils.check.PatternExpConstants;
import com.dream.utils.date.DateParseUtils;
import com.dream.utils.image.ImagePathType;
import com.dream.utils.security.PasswordUtils;
import com.dream.vo.base.First;
import com.dream.vo.base.FirstGroup;
import com.dream.vo.base.FourthGroup;
import com.dream.vo.base.Second;
import com.dream.vo.base.SecondGroup;
import com.dream.vo.base.Third;
import com.google.common.collect.Lists;


/**
 * 
 * @author Evan
 * @date 2013-8-29
 * 
 */
@GroupSequence({First.class, Second.class,Third.class, UserVO.class})  
public class UserVO implements Serializable{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 7247074194971630057L;
	
	@NotBlank(message = "err0001",groups = {First.class,FirstGroup.class})
	@Length( min = 4,max = 30, message = "err0003,4,30",groups = {Second.class,FirstGroup.class})  
	private String id;
	
	@NotBlank(message = "err0001",groups = {First.class,FirstGroup.class,FourthGroup.class})
	@Length( min = 6, max = 30,message = "err0003,6,30",groups = {Second.class,FirstGroup.class,FourthGroup.class})  
	private String password;
	
	@NotBlank(message = "err0001",groups = {First.class,FourthGroup.class})
	@Length( min = 6, max = 30,message = "err0003,6,30",groups = {Second.class,FourthGroup.class})  
	private String newPassword;
	
	@NotBlank(message = "err0001",groups = {First.class,FourthGroup.class})
	@Length( min = 6, max = 30,message = "err0003,6,30",groups = {Second.class,FourthGroup.class})  
	private String surePassword;
	
	@NotBlank(message = "err0001",groups = {First.class,SecondGroup.class})
	private String name;
	
	@NotBlank(message = "err0001",groups = {First.class,SecondGroup.class})
	 @Pattern(regexp = PatternExpConstants.MOBILE_PAT, message = "err0007", groups = {Second.class,SecondGroup.class})
	private String mobile;

	private String phone;
	
	private String birthday;
	
	private String status;
	
	private String address;
	
	private String rememberMe;
	
	private String imageFileId;
	
	private Long imageId;
	
	private String age;
	
	private String position;
	
	private String[] groups;
	
	private String group;
	
	private String email;
	
	private String gender;
	
	private Collection<UserStatus> userStatus;
	
	private String firstOrg;
	
	private String secondOrg;
	
	private Collection<Long> orgs = Lists.newArrayList();
	
	
	public Collection<Long> getOrgs() {
		return orgs;
	}

	public void setOrgs(Collection<Long> orgs) {
		this.orgs = orgs;
	}

	public String getFirstOrg() {
		return firstOrg;
	}

	public void setFirstOrg(String firstOrg) {
		this.firstOrg = firstOrg;
	}

	public String getSecondOrg() {
		return secondOrg;
	}

	public void setSecondOrg(String secondOrg) {
		this.secondOrg = secondOrg;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getGender() {
		return gender;
	}

	public void setGender(String gender) {
		this.gender = gender;
	}

	public String[] getGroups() {
		return groups;
	}

	public void setGroups(String[] groups) {
		this.groups = groups;
	}

	public String getGroup() {
		return group;
	}

	public void setGroup(String group) {
		this.group = group;
	}

	public String getPosition() {
		return position;
	}

	public void setPosition(String position) {
		this.position = position;
	}

	public String getAge() {
		return age;
	}

	public void setAge(String age) {
		this.age = age;
	}

	public Long getImageId() {
		return imageId;
	}

	public void setImageId(Long imageId) {
		this.imageId = imageId;
	}


	public String getRememberMe() {
		return rememberMe;
	}

	public void setRememberMe(String rememberMe) {
		this.rememberMe = rememberMe;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getPassword() {
		return PasswordUtils.md5Pwd(id,password);
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getNewPassword() {
		return PasswordUtils.md5Pwd(id,newPassword);
	}

	public void setNewPassword(String newPassword) {
		this.newPassword = newPassword;
	}

	public String getSurePassword() {
		return PasswordUtils.md5Pwd(id,surePassword);
	}

	public void setSurePassword(String surePassword) {
		this.surePassword = surePassword;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}


	public String getMobile() {
		return mobile;
	}


	public void setMobile(String mobile) {
		this.mobile = mobile;
	}


	public String getImageFileId() {
		return imageFileId;
	}

	public void setImageFileId(String imageFileId) {
		this.imageFileId = imageFileId;
	}

	
	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getBirthday() {
		return birthday;
	}

	public void setBirthday(String birthday) {
		this.birthday = birthday;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}
	
	public Collection<UserStatus> getUserStatus() {
		return userStatus;
	}

	public void setUserStatus(Collection<UserStatus> userStatus) {
		this.userStatus = userStatus;
	}

	public static String getUploadThumbPath(AppAbstractUser user){
		
		return new StringBuilder(ImagePathType.thumbnail.getImagePath())
		.append(user.getId())
		.append("/")
		.append(DateParseUtils.format(new Date(), "yyyyMMdd"))
		.append("/")
		.toString();
	}
	public static String getUploadEntirePath(AppAbstractUser user){
		
		return new StringBuilder(ImagePathType.entire.getImagePath())
		.append(user.getId())
		.append("/")
		.append(DateParseUtils.format(new Date(), "yyyyMMdd"))
		.append("/")
		.toString();
	}
	
	public String validateSurePwd(){
		
		if(!getSurePassword().equals(getNewPassword())){
			return "err0005";
		}else if(getSurePassword().equals(getPassword())){
			return "err0017";
		}
		return "";
	}
	
}
